// 登录。获取参数并发送登录信号给C++，执行登录过程。
function signIn(){
    var username = userNameField.text;
    var password = passwordField.text;

    rootView.qsSignIn(username, password, 0);

    disableUI();
}

// 登录时，禁用UI控件
function disableUI(){
    info.text = "正在登录...";

    setWidgetStatus(false);
}

// 恢复UI控件
function resumeUI(){
    info.text = "";

    setWidgetStatus(true);
}

// 设置控件状态
function setWidgetStatus(enabled){
    userNameField.enabled = enabled;
    passwordField.enabled = enabled;

    statusField.enabled = enabled;
    signInBtn.enabled = enabled;
    rememberPasswordBtn.enabled = enabled;
    registerBtn.enabled = enabled;
    autoLoginBtn.enabled = enabled;
    forgetPasswordBtn.enabled = enabled;
}

// 模拟JS中的setTimeout函数
function setTimeout(callback, delayTime) {
   timer.interval = delayTime;
   timer.repeat = false;
   timer.triggered.connect(callback);
   timer.start();
}

// 登录成功 事件处理器
function onSignInSucceed(){
    //console.debug("loginDialog.visible:", loginDialog.visible);
    if(loginDialog.visible){
        loginDialog.visible = false;
        loginDialog.hide();

        rootView.show();

        resumeUI();
    }
}

// 登录失败 事件处理器
function onSignInFailed(title, message) {
    messageDialog.title = title;
    messageDialog.text = message;
    messageDialog.visible = true;
}
